package main.java;

/**
 * @program: pratice
 * @author: 关键我是大怪
 * @create: 2021-09-10 15:56
 */
public class Test21_乘积小于K的子数组 {
    public static int numSubarrayProductLessThanK(int[] nums, int k) {
        if (k == 0) {
            return 0;
        }
        int left = 0;
        int cnt = 0;
        int sum = 1;
        for (int i = 0; i < nums.length; i++) {
            sum *= nums[i];
            while (left <= i && sum >= k) {
                sum /= nums[left++];
            }
            if (left <= i) {
                cnt += i - left + 1;
            }

        }
        return cnt;
    }

    public static void main(String[] args) {
        int[] a = new int[]{10, 5, 2, 6};
        int i = numSubarrayProductLessThanK(a, 100);
        System.out.println(i);
    }
}
